package com.caishi.lkx.exam.dto;

import lombok.Getter;

import java.io.Serializable;
import java.util.LinkedList;
import java.util.List;
import java.util.stream.Collectors;

public class UserPermissionDto<ID extends Serializable & Comparable<ID>> {

    /**
     * 用户的权限
     */
    @Getter
    private List<ID> user = new LinkedList<>();
    /**
     * 机构的权限
     */
    @Getter
    private List<ID> group = new LinkedList<>();

    /**
     * 所有权限
     */
    @Getter
    private List<ID> all = new LinkedList<>();

    public void setUser(List<ID> user) {
        this.user = user.stream().distinct().sorted(ID::compareTo).collect(Collectors.toList());
        addAll(user);
    }

    public void setGroup(List<ID> group) {
        this.group = group.stream().distinct().sorted(ID::compareTo).collect(Collectors.toList());
        addAll(group);
    }

    private void addAll(List<ID> ids) {
        all.addAll(ids);
        all = all.stream().distinct().sorted(ID::compareTo).collect(Collectors.toList());
    }
}
